package com.zlp.partice;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;

/**
 * @Author: zhulaiping
 * @Date: 2021/7/10 20:29
 */
class TimeMap {
    Map<String, TreeMap<Integer,String>>map;

    /** Initialize your data structure here. */
    public TimeMap() {
        map = new HashMap<>();
    }

    public void set(String key, String value, int timestamp) {
        TreeMap<Integer, String> treeMap = map.getOrDefault(key, new TreeMap<>());
        treeMap.put(timestamp,value);
        map.put(key,treeMap);
    }

    public String get(String key, int timestamp) {
        Map.Entry<Integer, String> entry = map.getOrDefault(key, new TreeMap<>()).floorEntry(timestamp);
        return entry==null?"":entry.getValue();
    }

    public int hIndex(int[] citations) {
        Arrays.sort(citations);
        int ret = 0;
        for (int i=0;i<citations.length;i++){
            if(i+1<=citations.length-i)
                ret = Math.max(ret,i+1);
        }
        return 0;
    }
}